// 高德地图API代理 - 公交路线规划
app.get('/amap/maps/direction_transit_integrated', async (req, res) => {
  const { origin, destination, city, cityd, strategy } = req.query;
  const key = '4449ac26963227ad33708de521f024c5';
  
  const apiUrl = new URL('https://restapi.amap.com/v3/direction/transit/integrated');
  apiUrl.searchParams.set('key', key);
  apiUrl.searchParams.set('origin', origin);
  apiUrl.searchParams.set('destination', destination);
  apiUrl.searchParams.set('city', city || '上海');
  apiUrl.searchParams.set('cityd', cityd || city || '上海');
  apiUrl.searchParams.set('extensions', 'all');
  
  // 如果有strategy参数，则添加（5表示地铁优先）
  if (strategy) {
    apiUrl.searchParams.set('strategy', strategy);
  }
  
  try {
    console.log('发送高德API请求:', apiUrl.toString());
    const response = await fetchAMapAPI(apiUrl.toString());
    // 记录响应结果的概况
    if (response && response.route && response.route.transits) {
      console.log(`公交路线规划成功，找到${response.route.transits.length}条路线`);
    }
    res.json(response);
  } catch (error) {
    console.error('高德地图API请求错误:', error);
    res.status(500).json({ error: error.message });
  }
}); 